<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>文件管理</title>
	<link rel="stylesheet" href="__ADMIN__/vendor/layui/css/layui.css">
	<script src="__ADMIN__/vendor/iconfont/iconfont.js"></script>
	<style>
		.fileicon i{font-size:1.8em;color:#FFE88C;-webkit-text-stroke: 1px #F1C95F;}
		.layui-table[lay-size="lg"] td, .layui-table[lay-size="lg"] th {
			padding: 15px 10px;
		}
		.filelink{color:#20A53A;}
		.filelink:hover{
			color:#333;
		}
		.cz{display:none;}
		tr:hover .cz{display: block;}
		/*@font-face {*/
			/*font-family: 'iconfont';*/
			/*src: url('__ADMIN__/vendor/iconfont/iconfont.eot');*/
			/*src: url('__ADMIN__/vendor/iconfont/iconfont.eot?#iefix') format('embedded-opentype'),*/
			/*url('__ADMIN__/vendor/iconfont/iconfont.woff') format('woff'),*/
			/*url('__ADMIN__/vendor/iconfont/iconfont.ttf') format('truetype'),*/
			/*url('__ADMIN__/vendor/iconfont/iconfont.svg#iconfont') format('svg');*/
		/*}*/
		/*.my-icon{*/
			/*font-family:"iconfont" !important;*/
			/*font-size:16px;font-style:normal;*/
			/*-webkit-font-smoothing: antialiased;*/
			/*-webkit-text-stroke-width: 0.2px;*/
			/*-moz-osx-font-smoothing: grayscale;*/
		/*}*/
		.my-icon {
			width: 1em; height: 1em;
			vertical-align: -0.15em;
			fill: currentColor;
			overflow: hidden;
			font-size:30px;
		}
	</style>
</head>
<body style="padding:15px;">
<div class="head-top">
	<a  href="?currdir={$curdir|iconv='GB2312','UTF-8',###}\.." class="layui-btn layui-btn-sm layui-btn-primary">
	  <i class="layui-icon">上级目录</i>
	</a>
	<button class="layui-btn layui-btn-sm layui-btn-primary" id="reload">
	  <i class="layui-icon">&#x1002;</i>
	</button>
	<button class="layui-btn layui-btn-sm layui-btn-danger">当前路径：{$curdir|iconv='GB2312','UTF-8',###}</button>
	<span class="layui-btn layui-btn-sm layui-btn-success" style="float:right;">共{$num.dir}个目录，{$num.file}个文件</span>
</div>
<div class="file-list">
	<table class="layui-table" lay-size="lg" lay-skin="line">
	  <thead>
		<tr>
		  <th>文件名</th>
		  <th>文件大小</th>
		  <th>缩略图</th>
		  <th>创建时间</th>
		  <th>最后修改时间</th>
		  <th style="text-align:right;width:300px;">操作</th>
		</tr> 
	  </thead>
	  <tbody>
	  {volist name="$dirs" id="v"}
		<tr>
		  <td class="fileicon">
			  <svg class="my-icon" aria-hidden="true">
				  <use xlink:href="{$v.icon}"></use>
			  </svg>
			  <a href="{$v.flag?'?currdir='.$v.currdir:'javascript:;'}">{$v.name|iconv='GB2312','UTF-8',###}</a>
		  </td>
		  <td>{$v.flag?"目录":size_format($v.size,2)}</td>
			<?php $p=urlencode($v['currdir']);?>
		  <td>{$p|getpics=###,40}</td>
		  <td>{$v.ctime|date="Y-m-d",###}</td>
		  <td>{$v.mtime|date="Y-m-d",###}</td>
		  <td>
			<span class="cz">
				<a class="filelink" href="javascript:;" onclick="DeleteFile('{$v.currdir|urlencode=###}')">删除</a> |
				{eq name="v.flag" value="0"}
				<a class="filelink" href="{:url('file/edit')}?file={$v.currdir|urlencode=###}">编辑</a> |
				{/eq}
				<a class="filelink" href="javascript:;" onclick="ReName('{$v.currdir|urlencode=###}','{$v.currdir|basenamecn=###}')">重命名</a>
				{eq name="v.flag" value="0"}

				 |<a class="filelink" href="{:url('file/download')}?currdir={$v.currdir|urlencode=###}">下载</a>
				{/eq}
			</span>
		  </td>
		</tr>
	  {/volist}
	  </tbody>
	</table>
	<div id="page"></div>
</div>
<script src="__ADMIN__/vendor/js/jquery.js"></script>
<script src="__ADMIN__/vendor/layui/layui.js"></script>
	<script>
        layui.use(['laypage','layer'], function(){
            var laypage = layui.laypage;
			var layer = layui.layer;
            //执行一个laypage实例
            laypage.render({
                elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
                ,count:{$page.count} //数据总数，从服务端得到
				,limit:{$page.limit}
				,curr:{$page.curr}
				,layout:['prev', 'page', 'next','skip']
				,jump: function(obj, first){
					//obj包含了当前分页的所有参数，比如：
					console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
					console.log(obj.limit); //得到每页显示的条数
					//首次不执行
					if(!first){
						//do something
						<?php $path=iconv('GB2312','UTF-8',$curdir.DIRECTORY_SEPARATOR);?>
						location.href="?&currdir={$path|urlencode=###}&page="+obj.curr;
					}
				}
            });
        });
        //文件删除
        //file 要删除文件的绝对路径
        function DeleteFile(file) {
            layer.confirm('确认要删除该文件（目录）吗?', {icon: 3, title:'温馨提示'}, function(index){
                //do something
                $.ajax({
                    type:'post',
                    url:"{:url('file/del')}",
                    data:{'file':file},
                    success:function (data) {
                        layer.msg(data.msg,{time:1000},function () {
                            location.reload();
                        });
                    }
                });
                layer.close(index);
            });

        }
		//重命名
        //file 要重命名文件/目录的绝对路径
		function ReName(file,filename) {
            layer.prompt({
                value:filename,
                title: '请输入新的文件名',
            },function(value, index, elem){
                $.ajax({
					type:"post",
					url:"{:url('file/renames')}",
					data:{'file':file,'filename':value},
					success:function (data) {
						layer.msg(data.msg,{time:1000},function () {
							if(data.code==1){
                                location.reload();
							}
                        });
                    }
				});
                layer.close(index);
            });
        }
		$(function(){
			$(window.parent.document).find('#righttitle').text($('title').text());
			$('#reload').on('click',function(){
				location.reload();
			})
		})
	</script>
</body>
</html>
